//
//  GuideViewController.swift
//  AudioToolProject
//
//  Created by 邹琳 on 2019/5/9.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit
import SnapKit

class GuideViewController: UIViewController {

    let scrollView:UIScrollView = {
        let scrollView = UIScrollView()
        scrollView.showsVerticalScrollIndicator = false
        scrollView.isPagingEnabled = true
        scrollView.bounces = false
        return scrollView
    }()
    
    let dataSource = ["2","1","3"]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.setupUI()
    }
    
    func setupUI(){
        view.addSubview(self.scrollView)
        
        scrollView.snp.makeConstraints { (make) in
            make.left.right.bottom.top.equalTo(self.view)
        }
        
        for (idx,val) in dataSource.enumerated(){
            let temp = UIImageView(image: UIImage(named: val))
            temp.frame = CGRect(x: UIScreen.main.bounds.width * CGFloat(idx), y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
            scrollView.addSubview(temp)
            
            if idx == dataSource.count - 1{
                let btn = UIButton(type: .custom)
                btn.backgroundColor = MainColor
                btn.layer.cornerRadius = 5
                btn.layer.masksToBounds = true
                btn.setTitle("欢迎进入".zlLocalizedString, for: .normal)
                scrollView.addSubview(btn)
                btn.frame = CGRect(x: temp.frame.minX + 50, y: UIScreen.main.bounds.height - 130, width: UIScreen.main.bounds.width - 100, height: 40)
                btn.addTarget(self, action: #selector(begin_action), for: .touchUpInside)
            }
        }
        
        scrollView.contentSize = CGSize(width: UIScreen.main.bounds.width * CGFloat(dataSource.count), height: 0)
    }

    
    @objc func begin_action(){
        UIApplication.shared.keyWindow?.rootViewController = RootViewController()
        UIApplication.shared.keyWindow?.makeKeyAndVisible()
    }
}
